package utils;

import javafx.animation.FadeTransition;
import javafx.event.EventHandler;
import javafx.event.EventTarget;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ProgressBar;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javafx.util.Duration;



/**
 * 封装一些通用的ui组件
 */
public class CommonComponent {

    public static void warningAlert(String title,String info){
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle(title);
        alert.setHeaderText(info);
        alert.setContentText(info);
        alert.showAndWait();
    }

    public static void errorAlert(String title,String info){
        Alert alert=new Alert(Alert.AlertType.ERROR);
        alert.setTitle(title);
        alert.setHeaderText(info);
        alert.setContentText(info);
        alert.showAndWait();
    }

    //创建一个进度条窗口显示进度
    public static ProgressBar createProgressBar(Stage progressStage){
        BorderPane border=new BorderPane();
        final HBox hb=new HBox();
        hb.setSpacing(5);
        hb.setAlignment(Pos.CENTER);
        hb.setMinWidth(300);
        border.setCenter(hb);
        Button button=new Button("确定");
        button.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                   progressStage.close();
            }
        });
        Scene scene=new Scene(border,400,100);
        progressStage.setScene(scene);
        progressStage.setTitle("正在执行中");
        ProgressBar pb=new ProgressBar(0);
        pb.setMinWidth(280);
        //hb 添加节点
        hb.getChildren().add(pb);
        hb.getChildren().add(button);
        progressStage.show();
        return pb;
    }

    //判断原路径和目标路径是否为空
    public static void handleTextFieldIsEmpty() {
        Alert alert = new Alert(Alert.AlertType.WARNING);
        alert.setContentText("请选择目标和原路径");
        alert.setTitle("警告");
        alert.setHeaderText("注意");
        alert.showAndWait();
    }

    public static String getPlatformBASeparator(String name) {
        return getPlatformSeparator() + name + getPlatformSeparator();
    }

    public static String getPlatformSeparator() {
        return CommandDefault.getPlatformSeparator();
    }


}
